local dingke = fk.CreateSkill {
  name = "wk_heg__dingke",
}

Fk:loadTranslationTable{
  ["wk_heg__dingke"] = "定科",
  [":wk_heg__dingke"] = "①其他角色使用其武将牌上技能描述中含有牌名的牌指定目标后，你可令其横置，然后此牌结算两次；②处于横置状态的角色武将牌上带有牌名描述的技能无效。",

  ["$wk_heg__dingke1"] = "一拜一起，未足为劳。",
  ["$wk_heg__dingke2"] = "直言观行，方能雍容风议。",
}

dingke:addEffect(fk.TargetSpecified, {
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    if not (player:hasSkill(dingke.name) and data.card and player ~= target and data.firstTarget and not target.chained) then return false end
    local all_names = {}
    for _, c in ipairs({target.general, target.deputyGeneral}) do
      for _, s in ipairs(Fk.generals[c]:getSkillNameList()) do
        local desc = Fk:translate(":"..s, "zh_CN")
        if string.find(desc, "【"..Fk:translate(data.card.name, "zh_CN").."】") or string.find(desc, "【"..Fk:translate(data.card.trueName, "zh_CN").."】") or
              string.find(desc, Fk:translate(data.card.name, "zh_CN")[1].."【"..Fk:translate(data.card.trueName, "zh_CN").."】") then
          table.insert(all_names, data.card.name)
        end
      end
    end
    if #all_names > 0 then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    target:setChainState(not target.chained)
    data.use.additionalEffect = 1
  end,
})

dingke:addEffect("invalidity", {
  invalidity_func = function(self, player, skill)
    if skill.name == "wk_heg__dingke" or skill == dingke then return false end
    if not table.find(Fk:currentRoom().alive_players, function(p) return p:hasShownSkill(dingke.name) end) or not player.chained then 
      return false 
    end
    local skills = {}
    for _, c in ipairs({player.general, player.deputyGeneral}) do
      for _, skill_name in ipairs(Fk.generals[c]:getSkillNameList()) do
        local skill_on = Fk.skills[skill_name]
        if skill_on:isPlayerSkill(player) then
          table.insertIfNeed(skills, skill_name)
        end
      end
    end
    if not table.contains(skills, skill.name) then 
      return false 
    end
    local desc = Fk:translate(":"..skill.name, "zh_CN")
    local card_table = {
      "slash",
      "jink",
      "peach",
      "analeptic",

      "dismantlement",
      "snatch",
      "duel",
      "collateral",
      "ex_nihilo",
      "nullification",
      "savage_assault",
      "archery_attack",
      "god_salvation",
      "amazing_grace",
      "iron_chain",
      "fire_attack",

      "lightning",
      "indulgence",
      "supply_shortage",

      "crossbow",
      "qinggang_sword",
      "ice_sword",
      "spear",
      "axe",
      "kylin_bow",
      "eight_diagram",
      "nioh_shield",
      "fan",
      "vine",
      "silver_lion",

      "wooden_ox",
      "sa__breastplate",
      "sa__blade",
      "sa__halberd",
      "iron_armor",
      "jade_seal",

      "befriend_attacking", 
      "known_both", 
      "await_exhausted", 
      "burning_camps", 
      "lure_tiger",
      "fight_together", 
      "alliance_feast", 
      "threaten_emperor",
      "sa__drowning",
      "imperial_order",

      "dragon_phoenix",
      "peace_spell",
      "luminous_pearl",
      "liulongcanjia",
    }
    for _, card_name in ipairs(card_table) do
      if string.find(desc, "【"..Fk:translate(card_name, "zh_CN").."】") or
            string.find(desc, Fk:translate(card_name, "zh_CN")[1].."【"..Fk:translate(card_name, "zh_CN").."】") then
        return true
      end
    end
  end,
})


return dingke
